using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using EIMS.Models.Enums;
using EIMS.Models.Identity;

namespace EIMS.Models
{
    /// <summary>
    /// 员工实体类
    /// </summary>
    public class Employee
    {
        [Key]
        public int Id { get; set; }

        [Required(ErrorMessage = "员工编号不能为空")]
        [MaxLength(20, ErrorMessage = "员工编号不能超过20个字符")]
        [Display(Name = "员工编号")]
        public string EmployeeNumber { get; set; } = string.Empty;

        [Required(ErrorMessage = "姓名不能为空")]
        [MaxLength(50, ErrorMessage = "姓名不能超过50个字符")]
        [Display(Name = "姓名")]
        public string Name { get; set; } = string.Empty;

        [Display(Name = "性别")]
        public Gender Gender { get; set; }

        [Column(TypeName = "date")]
        [DataType(DataType.Date)]
        [Display(Name = "出生日期")]
        public DateTime? DateOfBirth { get; set; }

        [Required(ErrorMessage = "手机号码不能为空")]
        [MaxLength(20, ErrorMessage = "手机号码不能超过20个字符")]
        [Display(Name = "手机号码")]
        public string PhoneNumber { get; set; } = string.Empty;

        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        [MaxLength(100, ErrorMessage = "邮箱不能超过100个字符")]
        [Display(Name = "邮箱")]
        public string Email { get; set; } = string.Empty;

        [MaxLength(50, ErrorMessage = "职位名称不能超过50个字符")]
        [Display(Name = "职位")]
        public string? Position { get; set; }

        [MaxLength(200, ErrorMessage = "地址不能超过200个字符")]
        [Display(Name = "地址")]
        public string Address { get; set; } = string.Empty;

        [Column(TypeName = "date")]
        [DataType(DataType.Date)]
        [Required(ErrorMessage = "入职日期不能为空")]
        [Display(Name = "入职日期")]
        public DateTime HireDate { get; set; }

        [Display(Name = "员工状态")]
        public EmployeeStatus Status { get; set; } = EmployeeStatus.Active;

        [Column(TypeName = "date")]
        [DataType(DataType.Date)]
        [Display(Name = "离职日期")]
        public DateTime? TerminationDate { get; set; }

        [Display(Name = "是否启用")]
        public bool IsActive { get; set; } = true;

        [Display(Name = "创建时间")]
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        [Display(Name = "更新时间")]
        public DateTime? UpdatedAt { get; set; }

        // 外键
        [Display(Name = "部门")]
        public int? DepartmentId { get; set; }

        // 导航属性
        [ForeignKey("DepartmentId")]
        [Display(Name = "部门")]
        public virtual Department? Department { get; set; }

        // 导航属性 - 该员工的所有历史记录
        public virtual ICollection<EmployeeHistory> EmployeeHistories { get; set; } = new List<EmployeeHistory>();

        // 可选：与系统用户的关联
        public string? UserId { get; set; }
        
        [ForeignKey("UserId")]
        public virtual ApplicationUser? User { get; set; }
    }
} 